%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Reproducing Table 5 of the paper:
%Reis, Ricardo (2006) "Inattentive Producers," Review of Economic Studies.
%Written by: Ricardo Reis
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This program produces the  MA representations for the shocks
% Uses white noise for g_m and MA(1) with -1 for g_a, according with data
% Needs: alpha, lambda, upper
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%STEP 1: INPUT THE MA REPRESENTATION FOR DRIVING SHOCKS
%White noise nominal income: g_m = epsilon
rho(1,1)=1;
for j=1:upper+1
    rho(j+1,1)=0;
end
%MA(1) for technology growth: g_a = epsilon - epsilon_t-1 
eta(1,1)=1;
eta(2,1)=-1;
for j=2:upper+1
    eta(j+1,1)=0;
end
%useful sums
sum_lambda(1,1)=1;
sum_rho(1,1)=rho(1,1);
sum_eta(1,1)=eta(1,1);
for j=1:upper+1
    sum_lambda(j+1,1)=sum_lambda(j,1)+(1-lambda)^j;
    sum_rho(j+1,1)=sum_rho(j,1)+rho(j+1,1);
    sum_eta(j+1,1)=sum_eta(j,1)+eta(j+1,1);
end
   
%STEP 2: SOLVE FOR INFLATION
%gamma is on m shocks, whereas csi is on tech shocks
gamma(1,1)=alpha*lambda/(1-lambda*(1-alpha));
sum_gamma(1,1)=gamma(1,1);
csi(1,1)=alpha*lambda/(1-lambda*(1-alpha));
sum_csi(1,1)=csi(1,1);
for j=1:upper
    temp1=1-lambda*(1-alpha)*sum_lambda(j+1,1);
    %m part
    temp2=-sum_gamma(j,1)+sum_rho(j+1,1)+rho(j+1,1)*(sum_lambda(j+1,1)-1);
    gamma(j+1,1)=alpha*lambda*temp2/temp1;
    sum_gamma(j+1,1)=sum_gamma(j,1)+gamma(j+1,1);
    %tech part
    temp3=-sum_csi(j,1)+sum_eta(j+1,1)+eta(j+1,1)*(sum_lambda(j+1,1)-1);
    csi(j+1,1)=alpha*lambda*temp3/temp1;
    sum_csi(j+1,1)=sum_csi(j,1)+csi(j+1,1);
end
csi=-csi;
sum_csi=-sum_csi;

clear j temp1 temp2 temp3 sum_gamma sum_csi sum_lambda sum_rho sum_eta